/**
 * @author 龙小虬
 * @date 2021/4/22 12:12
 */
public class Singleton {
    private static volatile Singleton singleton03;

    public static Singleton getInstance() {
        // 第一次检查
        if (singleton03 == null) {
            //第二次检查
            synchronized (Singleton.class) {
                if (singleton03 == null) {
                    singleton03 = new Singleton();
                }
            }
        }
        return singleton03;
    }

    public static void main(String[] args) {
        Singleton instance1 = Singleton.getInstance();
        Singleton instance2 = Singleton.getInstance();
        System.out.println(instance1==instance2);
    }
}
